package exercise;

// https://leetcode.cn/problems/jump-game-ii/
public class L230703_I {
    public int jump(int[] nums) {
        int ans = 0;
        int side = 0;
        int maxSide = 0;

        if (nums.length == 1) {
            return 0;
        }
        for (int i = 0; i < nums.length; i++) {
            maxSide = Math.max(maxSide, nums[i]+i);

            if (i == side) {
                side = maxSide;
                ans++;
            }

            if (side >= nums.length-1) {
                break;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        L230703_I t = new L230703_I();
        System.out.println(t.jump(new int[]{2,3,0,1,4}));
    }
}
